/**
 * Created by zhuo on 2017/8/1.
 */
var express = require('express');
var router = express.Router();
import mockCompanyData from './mockData/companysMock.json';
// var mockCompanyData = require('./mockData/companysMock2.json');
var mockCompanyTypeByIdData = require("./mockData/organizationListById.json");
var result = require("./mockData/operationResult.json");

/* GET users listing. */
router.get('/getOrganizationList', function (req, res, next) {
    console.info("get organization list now... ");
    mockCompanyData.draw = req.query.draw;
    res.json(mockCompanyData);
});
router.get('/getOrganizationListByTypeId', function (req, res, next) {
    console.info("get organization Type by id now...");
    res.json(mockCompanyTypeByIdData);
});

var updateAndCreateResult = {
    "message": "测试内容684j",
    "organization": {
        "createTime": 37755,
        "id": "公司",
        "name": "公司",
        "organizationTypeNameName": "测试内容3kl2",
        "parentOrganizationName": "测试内容n2y8",
        "remark": "测试内容jp7r"
    },
    "result": true
};


router.post('/create', function (req, res, next) {
    console.info("create call! :" + JSON.stringify(req.body));
    res.send(updateAndCreateResult);
})
router.post('/update', function (req, res, next) {
    console.info("update call! :" + JSON.stringify(req.body));
    res.send(updateAndCreateResult);
})

router.post('/delete', function (req, res, next) {
    console.info("delete company authorities now... :" + JSON.stringify(req.body));
    res.json(result);
});

/**
 * ACS 2017/10/23
 */
router.get('/typeList', function (req, res, next) {
    res.json({
        "message": 1,
        "result": true,
        "resultData": [
            {
                "id": 1,
                "name": 1
            },
            {
                "id": 2,
                "name": 2
            },
            {
                "id": 3,
                "name": 3
            },
            {
                "id": 4,
                "name": 4
            },
            {
                "id": 5,
                "name": 5
            },
        ]
    })
})
router.get('/list', function (req, res, next) {
    res.json({
        draw: req.query.draw,
        recordsFiltered: 555,
        recordsTotal: 10000,
        data: [
            {
                "id": "11",
                "name": "海辰公司中山分公司",
                "address": "广东省中山市",
                "groupList": "石岐区社区",
                "contact": "xxxxx",
                "phone": "13xxxxxxxxx",
                "updateTime": 1501837059487,
                "createUser": "超级管理员",
                "createTime": "2015/4/13 15:21:56",
                "organizationTypeName": "分公司/部门",
                "remark": "xxxxx"
            },
            {
                "id": "1",
                "name": "五桂山长命水村委会",
                "address": "广东省中山市五桂山长命水村",
                "groupList": "石岐区社区",
                "contact": "xxxxx",
                "phone": "13xxxxxxxxx",
                "updateTime": 1501837059487,
                "createUser": "超级管理员",
                "createTime": "2015/4/13 15:21:56",
                "organizationTypeName": "居委会/村委会",
                "remark": "xxxxx"
            },
            {
                "id": "2",
                "name": "东升分局荣兴派出所",
                "address": "广东省中山市东升镇裕民村",
                "groupList": "东升社区",
                "contact": "xxxxx",
                "phone": "13xxxxxxxxx",
                "updateTime": 1501837059487,
                "createUser": "超级管理员",
                "createTime": "2014/12/4 13:21:09",
                "organizationTypeName": "公安局/派出所",
                "remark": "xxxx"
            },
            {
                "id": "3",
                // "name": "小区管理员",
                "name": "五桂山长命水派出所",
                "address": "广东省中山市五桂山长命水村",
                "groupList": "黄圃社区",
                "contact": "xxxxx",
                "phone": "13xxxxxxxxx",
                "createUser": "超级管理员",
                "updateTime": 1501837059487,
                "createTime": "2014/9/29 15:40:25",
                "organizationTypeName": "公安局/派出所",
                "remark": "xxxx"
            },
            {
                "id": "4",
                "name": "五桂山分局",
                "address": "广东省中山市五桂山",
                "groupList": "东升社区",
                "contact": "xxxx",
                "phone": "13xxxxxxxxx",
                "updateTime": 1501837059487,
                "createUser": "超级管理员",
                "createTime": "2014/9/29 16:03:05",
                "organizationTypeName": "公安局/派出所",
                "remark": "xxxxx"
            },
            {
                "id": "5",
                "name": "联心路29号",
                "address": "广东省中山市古镇冈东村联心路29号",
                "groupList": "古镇社区",
                "contact": "xxxx",
                "phone": "13xxxxxxxxx",
                "createUser": "数据录入员",
                "updateTime": 1501837059487,
                "createTime": "2014/9/29 15:49:54",
                "organizationTypeName": "小区/建筑群",
                "remark": "xxxx"
            }
        ]
    })
})

router.get('/groupList', function (req, res, next) {
    if (req.body.id == 'S') {
        req.body.id = 0
    }
    var calculatedData = req.body.id * 2 + 1
    res.json({
        "message": "测试内容9so1",
        "result": 1,
        "resultData": [
            {
                "id": calculatedData,
                "name": calculatedData
            },
            {
                "id": calculatedData + 1,
                "name": calculatedData + 1
            },
        ]
    })
})
router.post('/add', function (req, res, next) {
    res.json({
        message: 1,
        result: true,
        resultData: {
            "id": "0",
            "name": "我日你爹",
            "address": "广东省中山市古镇冈东村联心路29号",
            "groupList": "古镇社区",
            "contact": "xxxx",
            "phone": "13xxxxxxxxx",
            "createUser": "数据录入员",
            "updateTime": 1501837059487,
            "createTime": "2014/9/29 15:49:54",
            "organizationTypeName": "小区/建筑群",
            "remark": "xxxx"
        }
    })
})

module.exports = router;
/**
 * Created by zhuo on 2017/8/1.
 */
